<!DOCTYPE html><html><head><title>Ext.Function | Ext JS 4.0 Documentation</title><script type="text/javascript" src="../ext-all.js"></script><link rel="stylesheet" href="../reset.css" type="text/css"><link rel="stylesheet" href="../scrollbars.css" type="text/css"><link rel="stylesheet" href="../docs.css" type="text/css"><link id="styleCss" rel="stylesheet" href="../style.css" type="text/css"><script type="text/javascript" src="../prettify.js"></script><link rel="stylesheet" href="../prettify.css" type="text/css"><!-- link(rel: 'stylesheet', href: req.baseURL + '/css/ext4.css', type: 'text/css')--><link rel="shortcut icon" type="image/ico" href="../favicon.ico"><!--[if IE]>
<style type="text/css">.head-band { display: none; }
.header { border: 0; top: 0; left: 0px; background: url(../header.gif) repeat-x; }
.doc-tab .members .member a.more { background-color: #efefef; }
</style><link rel="stylesheet" href="/new/css/ie.css" type="text/css"><![endif]-->
</head><body id="ext-body" class="iScroll"><div id="notice" class="notice">For up to date documentation and features, visit 
<a href="http://docs.sencha.com/ext-js/4-0">http://docs.sencha.com/ext-js/4-0</a></div><div class="wrapper"><div class="head-band"></div><div class="header"><h2><a href="../index.html">Sencha Documentation</a></h2></div><div id="search"><form><input type="text" placeholder="Search" id="search-field" autocomplete="off" name="q"></form><div id="search-box"></div></div><div id="treePanel"></div><div id="container"><script type="text/javascript">

    req = {
        liveURL: '.',
        standAloneMode: true,
        origDocClass: 'Ext.Function',
        docClass: 'Ext.Function',
        docReq: 'Ext.Function',
        version: '4.0',
        baseURL: '.',
        baseDocURL: '.',
        baseProdURL: '.'
    };

    clsInfo = {};



</script>

<script type="text/javascript" src="../search.js"></script>
<!--script type="text/javascript" src="/new/javascripts/app/examples.js"></script-->
<script type="text/javascript" src="../class_tree.js"></script>
<script type="text/javascript" src="../class_doc.js"></script>
<script type="text/javascript">
    req.source = 'Function.html#Ext-Function';
    clsInfo = {"methods":["alias","bind","createBuffered","createDelayed","createInterceptor","createSequence","createThrottled","defer","flexSetter","pass"],"cfgs":[],"properties":[],"events":[],"subclasses":[]};
    Ext.onReady(function() {
        Ext.create('Docs.classPanel');
    });
</script><div id="top-block" class="top-block"><h1 id="clsTitle" class="cls"><a href="../source/Function.html#Ext-Function" target="_blank">Ext.Function</a></h1></div><div id="docContent"><div id="doc-overview-content"><div class="lft"><p>A collection of useful static methods to deal with function callbacks</p>
<div class="members"><div class="m-methods"><a name="methods"></a><div class="definedBy">Defined By</div><h3 class="mth p">Methods</h3><div id="method-alias" class="member f ni"><a href="Ext.Function.html#method-alias" rel="method-alias" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-alias" class="viewSource">view source</a></div><a name="alias"></a><a name="method-alias"></a><a href="Ext.Function.html#" rel="method-alias" class="cls expand">alias</a>(
<span class="pre">Object/Function object, String methodName</span>)
 : Function</div><div class="description"><div class="short">Create an alias to the provided method property with name methodName of object.
Note that the execution scope will st...</div><div class="long"><p>Create an alias to the provided method property with name <code>methodName</code> of <code>object</code>.
Note that the execution scope will still be bound to the provided <code>object</code> itself.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">object</span> : Object/Function<div class="sub-desc">
</div></li><li><span class="pre">methodName</span> : String<div class="sub-desc">
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;<p>aliasFn</p>
</li></ul></div></div></div><div id="method-bind" class="member ni"><a href="Ext.Function.html#method-bind" rel="method-bind" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-bind" class="viewSource">view source</a></div><a name="bind"></a><a name="method-bind"></a><a href="Ext.Function.html#" rel="method-bind" class="cls expand">bind</a>(
<span class="pre">Function fn, [Object scope], [Array args], [Boolean/Number appendArgs]</span>)
 : Function</div><div class="description"><div class="short">Create a new function from the provided fn, change this to the provided scope, optionally
overrides arguments for the...</div><div class="long"><p>Create a new function from the provided <code>fn</code>, change <code>this</code> to the provided scope, optionally
overrides arguments for the call. (Defaults to the arguments passed by the caller)</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>The function to delegate.</p>
</div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
<b>If omitted, defaults to the browser window.</b></p>
</div></li><li><span class="pre">args</span> : Array<div class="sub-desc"><p>(optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)</p>
</div></li><li><span class="pre">appendArgs</span> : Boolean/Number<div class="sub-desc"><p>(optional) if True args are appended to call args instead of overriding,
if a number the args are inserted at the specified position</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;<p>The new function</p>
</li></ul></div></div></div><div id="method-createBuffered" class="member ni"><a href="Ext.Function.html#method-createBuffered" rel="method-createBuffered" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-createBuffered" class="viewSource">view source</a></div><a name="createBuffered"></a><a name="method-createBuffered"></a><a href="Ext.Function.html#" rel="method-createBuffered" class="cls expand">createBuffered</a>(
<span class="pre">Function fn, Number buffer, [Object scope], [Array args]</span>)
 : Function</div><div class="description"><div class="short">Creates a delegate function, optionally with a bound scope which, when called, buffers
the execution of the passed fu...</div><div class="long"><p>Creates a delegate function, optionally with a bound scope which, when called, buffers
the execution of the passed function for the configured number of milliseconds.
If called again within that period, the impending invocation will be canceled, and the
timeout period will begin again.</p>

<h3 class="pa">Parameters</h3><ul><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>The function to invoke on a buffered timer.</p>
</div></li><li><span class="pre">buffer</span> : Number<div class="sub-desc"><p>The number of milliseconds by which to buffer the invocation of the
function.</p>
</div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(optional) The scope (<code><b>this</b></code> reference) in which
the passed function is executed. If omitted, defaults to the scope specified by the caller.</p>
</div></li><li><span class="pre">args</span> : Array<div class="sub-desc"><p>(optional) Override arguments for the call. Defaults to the arguments
passed by the caller.</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;<p>A function which invokes the passed function after buffering for the specified time.</p>
</li></ul></div></div></div><div id="method-createDelayed" class="member ni"><a href="Ext.Function.html#method-createDelayed" rel="method-createDelayed" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-createDelayed" class="viewSource">view source</a></div><a name="createDelayed"></a><a name="method-createDelayed"></a><a href="Ext.Function.html#" rel="method-createDelayed" class="cls expand">createDelayed</a>(
<span class="pre">Function fn, Number delay, [Object scope], [Array args], [Boolean/Number appendArgs]</span>)
 : Function</div><div class="description"><div class="short"><p>Creates a delegate (callback) which, when called, executes after a specific delay.</p>
</div><div class="long"><p>Creates a delegate (callback) which, when called, executes after a specific delay.</p>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>The function which will be called on a delay when the returned function is called.
Optionally, a replacement (or additional) argument list may be specified.</p>
</div></li><li><span class="pre">delay</span> : Number<div class="sub-desc"><p>The number of milliseconds to defer execution by whenever called.</p>
</div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(optional) The scope (<code>this</code> reference) used by the function at execution time.</p>
</div></li><li><span class="pre">args</span> : Array<div class="sub-desc"><p>(optional) Override arguments for the call. (Defaults to the arguments passed by the caller)</p>
</div></li><li><span class="pre">appendArgs</span> : Boolean/Number<div class="sub-desc"><p>(optional) if True args are appended to call args instead of overriding,
if a number the args are inserted at the specified position.</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;<p>A function which, when called, executes the original function after the specified delay.</p>
</li></ul></div></div></div><div id="method-createInterceptor" class="member ni"><a href="Ext.Function.html#method-createInterceptor" rel="method-createInterceptor" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-createInterceptor" class="viewSource">view source</a></div><a name="createInterceptor"></a><a name="method-createInterceptor"></a><a href="Ext.Function.html#" rel="method-createInterceptor" class="cls expand">createInterceptor</a>(
<span class="pre">Function origFn, Function newFn, [Object scope], [Mixed returnValue]</span>)
 : Function</div><div class="description"><div class="short">Creates an interceptor function. The passed function is called before the original one. If it returns false,
the orig...</div><div class="long"><p>Creates an interceptor function. The passed function is called before the original one. If it returns false,
the original one is not called. The resulting function returns the results of the original function.
The passed function is called with the parameters of the original function. Example usage:</p>

<pre><code>var sayHi = function(name){
    alert('Hi, ' + name);
}

sayHi('Fred'); // alerts "Hi, Fred"

// create a new function that validates input without
// directly modifying the original function:
var sayHiToFriend = Ext.Function.createInterceptor(sayHi, function(name){
    return name == 'Brian';
});

sayHiToFriend('Fred');  // no alert
sayHiToFriend('Brian'); // alerts "Hi, Brian"
     </code></pre>

<h3 class="pa">Parameters</h3><ul><li><span class="pre">origFn</span> : Function<div class="sub-desc"><p>The original function.</p>
</div></li><li><span class="pre">newFn</span> : Function<div class="sub-desc"><p>The function to call before the original</p>
</div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
<b>If omitted, defaults to the scope in which the original function is called or the browser window.</b></p>
</div></li><li><span class="pre">returnValue</span> : Mixed<div class="sub-desc"><p>(optional) The value to return if the passed function return false (defaults to null).</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;<p>The new function</p>
</li></ul></div></div></div><div id="method-createSequence" class="member ni"><a href="Ext.Function.html#method-createSequence" rel="method-createSequence" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-createSequence" class="viewSource">view source</a></div><a name="createSequence"></a><a name="method-createSequence"></a><a href="Ext.Function.html#" rel="method-createSequence" class="cls expand">createSequence</a>(
<span class="pre">Function origFn, Function newFn, [Object scope]</span>)
 : Function</div><div class="description"><div class="short">Create a combined function call sequence of the original function + the passed function.
The resulting function retur...</div><div class="long"><p>Create a combined function call sequence of the original function + the passed function.
The resulting function returns the results of the original function.
The passed function is called with the parameters of the original function. Example usage:</p>

<pre><code>var sayHi = function(name){
    alert('Hi, ' + name);
}

sayHi('Fred'); // alerts "Hi, Fred"

var sayGoodbye = Ext.Function.createSequence(sayHi, function(name){
    alert('Bye, ' + name);
});

sayGoodbye('Fred'); // both alerts show
</code></pre>

<h3 class="pa">Parameters</h3><ul><li><span class="pre">origFn</span> : Function<div class="sub-desc"><p>The original function.</p>
</div></li><li><span class="pre">newFn</span> : Function<div class="sub-desc"><p>The function to sequence</p>
</div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(optional) The scope (this reference) in which the passed function is executed.
If omitted, defaults to the scope in which the original function is called or the browser window.</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;<p>The new function</p>
</li></ul></div></div></div><div id="method-createThrottled" class="member ni"><a href="Ext.Function.html#method-createThrottled" rel="method-createThrottled" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-createThrottled" class="viewSource">view source</a></div><a name="createThrottled"></a><a name="method-createThrottled"></a><a href="Ext.Function.html#" rel="method-createThrottled" class="cls expand">createThrottled</a>(
<span class="pre">Object fn, Object interval, [Object scope]</span>)
 : Function</div><div class="description"><div class="short">Creates a throttled version of the passed function which, when called repeatedly and
rapidly, invokes the passed func...</div><div class="long"><p>Creates a throttled version of the passed function which, when called repeatedly and
rapidly, invokes the passed function only after a certain interval has elapsed since the
previous invocation.</p>




<p>This is useful for wrapping functions which may be called repeatedly, such as
a handler of a mouse move event when the processing is expensive.</p>

<h3 class="pa">Parameters</h3><ul><li><span class="pre">fn</span> : Object<div class="sub-desc"><p>{Function} The function to execute at a regular time interval.</p>
</div></li><li><span class="pre">interval</span> : Object<div class="sub-desc"><p>{Number} The interval <b>in milliseconds</b> on which the passed function is executed.</p>
</div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(optional) The scope (<code><b>this</b></code> reference) in which
the passed function is executed. If omitted, defaults to the scope specified by the caller.</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;<p>A function which invokes the passed function at the specified interval.</p>
</li></ul></div></div></div><div id="method-defer" class="member ni"><a href="Ext.Function.html#method-defer" rel="method-defer" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-defer" class="viewSource">view source</a></div><a name="defer"></a><a name="method-defer"></a><a href="Ext.Function.html#" rel="method-defer" class="cls expand">defer</a>(
<span class="pre">Function fn, Number millis, [Object scope], [Array args], [Boolean/Number appendArgs]</span>)
 : Number</div><div class="description"><div class="short">Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:

var sa...</div><div class="long"><p>Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:</p>

<pre><code>var sayHi = function(name){
    alert('Hi, ' + name);
}

// executes immediately:
sayHi('Fred');

// executes after 2 seconds:
Ext.Function.defer(sayHi, 2000, this, ['Fred']);

// this syntax is sometimes useful for deferring
// execution of an anonymous function:
Ext.Function.defer(function(){
    alert('Anonymous');
}, 100);
     </code></pre>

<h3 class="pa">Parameters</h3><ul><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>The function to defer.</p>
</div></li><li><span class="pre">millis</span> : Number<div class="sub-desc"><p>The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)</p>
</div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
<b>If omitted, defaults to the browser window.</b></p>
</div></li><li><span class="pre">args</span> : Array<div class="sub-desc"><p>(optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)</p>
</div></li><li><span class="pre">appendArgs</span> : Boolean/Number<div class="sub-desc"><p>(optional) if True args are appended to call args instead of overriding,
if a number the args are inserted at the specified position</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Number</span>&nbsp; &nbsp;<p>The timeout id that can be used with clearTimeout</p>
</li></ul></div></div></div><div id="method-flexSetter" class="member ni"><a href="Ext.Function.html#method-flexSetter" rel="method-flexSetter" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-flexSetter" class="viewSource">view source</a></div><a name="flexSetter"></a><a name="method-flexSetter"></a><a href="Ext.Function.html#" rel="method-flexSetter" class="cls expand">flexSetter</a>(
<span class="pre">Function setter</span>)
 : Function</div><div class="description"><div class="short">A very commonly used method throughout the framework. It acts as a wrapper around another method
which originally acc...</div><div class="long"><p>A very commonly used method throughout the framework. It acts as a wrapper around another method
which originally accepts 2 arguments for <code>name</code> and <code>value</code>.
The wrapped function then allows "flexible" value setting of either:</p>

<ul>
     <li><code>name</code> and <code>value</code> as 2 arguments</li>
     <li>one single object argument with multiple key - value pairs</li>
</ul>


<p>For example:</p>

<pre><code>var setValue = Ext.Function.flexSetter(function(name, value) {
    this[name] = value;
});

// Afterwards
// Setting a single name - value
setValue('name1', 'value1');

// Settings multiple name - value pairs
setValue({
    name1: 'value1',
    name2: 'value2',
    name3: 'value3'
});
</code></pre>

<h3 class="pa">Parameters</h3><ul><li><span class="pre">setter</span> : Function<div class="sub-desc">
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;<p>flexSetter</p>
</li></ul></div></div></div><div id="method-pass" class="member ni"><a href="Ext.Function.html#method-pass" rel="method-pass" class="expand more ar"><span>&nbsp;</span></a><div class="title"><div class="meta"><a href="Ext.Function.html" class="definedIn docClass">Ext.Function</a><br/><a href="../source/Function.html#Ext-Function-method-pass" class="viewSource">view source</a></div><a name="pass"></a><a name="method-pass"></a><a href="Ext.Function.html#" rel="method-pass" class="cls expand">pass</a>(
<span class="pre">Function fn, Array args, [Object scope]</span>)
 : Function</div><div class="description"><div class="short">Create a new function from the provided fn, the arguments of which are pre-set to args.
New arguments passed to the n...</div><div class="long"><p>Create a new function from the provided <code>fn</code>, the arguments of which are pre-set to <code>args</code>.
New arguments passed to the newly created callback when it's invoked are appended after the pre-set ones.
This is especially useful when creating callbacks.
For example:</p>

<pre><code>var originalFunction = function(){
    alert(Ext.Array.from(arguments).join(' '));
};

var callback = Ext.Function.pass(originalFunction, ['Hello', 'World']);

callback(); // alerts 'Hello World'
callback('by Me'); // alerts 'Hello World by Me'
</code></pre>
<h3 class="pa">Parameters</h3><ul><li><span class="pre">fn</span> : Function<div class="sub-desc"><p>The original function</p>
</div></li><li><span class="pre">args</span> : Array<div class="sub-desc"><p>The arguments to pass to new callback</p>
</div></li><li><span class="pre">scope</span> : Object<div class="sub-desc"><p>(optional) The scope (<code><b>this</b></code> reference) in which the function is executed.</p>
</div></li></ul><h3 class="pa">Returns</h3><ul><li><span class="pre">Function</span>&nbsp; &nbsp;<p>The new callback function</p>
</li></ul></div></div></div></div></div></div></div><div id="pageContent"></div></div></div></div></body></html>